Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

skip updating when external binding is existed #128932

Merged
merged 1 commit into from
Aug 21, 2024

Conversation

bvanjoi
Copy link
Contributor

@bvanjoi bvanjoi commented Aug 10, 2024

Fixes #128813

For following code:

extern crate core;

fn f() {
    use ::core;
}

macro_rules! m {
    () => {
        extern crate std as core;
    };
}

m!();

fn main() {}
  • In the first loop, we define extern crate core and use ::core will be referred to core (yes, it does not consider if there are some macros that are not expanded. Ideally, this should be delayed if there are some unexpanded macros in the root, but I didn't change it like that because it seems like a huge change).
  • Then m is expanded, which makes extern_prelude('core') return std rather than core, causing the inconsistency.

r? @petrochenkov

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 10, 2024
@petrochenkov
Copy link
Contributor

Could you also add a test case for a crate that is not originally in the extern prelude due to command line options or built-ins, like core?

extern crate foo;

macro_rules! second_foo {
    () => {
        extern crate std as foo;
    };
}

second_foo!();

fn main() {
    use ::foo;
}

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 14, 2024
@rustbot rustbot added A-testsuite Area: The testsuite used to check the correctness of rustc T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Aug 16, 2024
@bvanjoi
Copy link
Contributor Author

bvanjoi commented Aug 16, 2024

In the latest patch:

  • rename issue-95992-extern-2.rs into empty.rs
  • rename issue-95992-extern-1.rs into issue-95992-extern.rs
  • skip updating the external binding if it exists.

@bvanjoi
Copy link
Contributor Author

bvanjoi commented Aug 17, 2024

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 17, 2024
@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 19, 2024
@bvanjoi bvanjoi changed the title make extern crate x as y under macro as an error when y is module skip updating when external binding is existed Aug 19, 2024
@petrochenkov
Copy link
Contributor

Thanks!
@bors r+

@bors
Copy link
Contributor

bors commented Aug 20, 2024

📌 Commit df019a9 has been approved by petrochenkov

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 20, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 20, 2024
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#128662 (Lint on tail expr drop order change in Edition 2024)
 - rust-lang#128932 (skip updating when external binding is existed)
 - rust-lang#129270 (Don't consider locals to shadow inner items' generics)
 - rust-lang#129277 (Update annotate-snippets to 0.11)
 - rust-lang#129294 (Stabilize `iter::repeat_n`)
 - rust-lang#129308 (fix: simple typo in compiler directory)
 - rust-lang#129309 (ctfe: make CompileTimeInterpCx type alias public)
 - rust-lang#129314 (fix a broken link in `mir/mod.rs`)
 - rust-lang#129318 (Remove unneeded conversion to `DefId` for `ExtraInfo`)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 21, 2024
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#128662 (Lint on tail expr drop order change in Edition 2024)
 - rust-lang#128932 (skip updating when external binding is existed)
 - rust-lang#129270 (Don't consider locals to shadow inner items' generics)
 - rust-lang#129277 (Update annotate-snippets to 0.11)
 - rust-lang#129294 (Stabilize `iter::repeat_n`)
 - rust-lang#129308 (fix: simple typo in compiler directory)
 - rust-lang#129309 (ctfe: make CompileTimeInterpCx type alias public)
 - rust-lang#129314 (fix a broken link in `mir/mod.rs`)
 - rust-lang#129318 (Remove unneeded conversion to `DefId` for `ExtraInfo`)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 2e58d62 into rust-lang:master Aug 21, 2024
6 checks passed
@rustbot rustbot added this to the 1.82.0 milestone Aug 21, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Aug 21, 2024
Rollup merge of rust-lang#128932 - bvanjoi:issue-128813, r=petrochenkov

skip updating when external binding is existed

Fixes rust-lang#128813

For following code:

```rs
extern crate core;

fn f() {
    use ::core;
}

macro_rules! m {
    () => {
        extern crate std as core;
    };
}

m!();

fn main() {}
```

- In the first loop, we define `extern crate core` and `use ::core` will be referred to `core` (yes, it does not consider if there are some macros that are not expanded. Ideally, this should be delayed if there are some unexpanded macros in the root, but I didn't change it like that because it seems like a huge change).
- Then `m` is expanded, which makes `extern_prelude('core')` return `std` rather than `core`, causing the inconsistency.

r? `@petrochenkov`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ICE: inconsistent resolution for an import
4 participants